using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using THSLib;

namespace THSERP.BaseProvider
{
    public partial class guiCustomizeToolbarForm : THSERPScreen
    {
        THSList<STToolbarsInfo> lstMainFormToolbar;
        public guiCustomizeToolbarForm()
        {
            InitializeComponent();
            lstMainFormToolbar = new THSList<STToolbarsInfo>();
            CustomizeMainFormToolbar();
        }

        private void CustomizeMainFormToolbar()
        {
            STToolbarsController objToolbarsController = new STToolbarsController();
            DataSet ds = objToolbarsController.GetSTToolbarsBySTModuleIDAndSTUserGroupID(0, 0);
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                STToolbarsInfo objToolbarsInfo = (STToolbarsInfo)objToolbarsController.GetObjectFromDataRow(row);
                STModulesInfo objModulesInfo = (STModulesInfo)new STModulesController().GetObjectByName(objToolbarsInfo.STToolbarTag);
                if (objModulesInfo != null)
                {
                    if (THSApp.HasPrivilege(objToolbarsInfo.STToolbarPrivilege, objModulesInfo.STModuleID))
                    {
                        lstMainFormToolbar.Add(objToolbarsInfo);
                    }
                }
            }

            fld_dgvMainFormToolbar.OptionsView.ShowGroupPanel = false;
            fld_dgcMainFormToolbar.DataSource = lstMainFormToolbar;
            fld_dgvMainFormToolbar.RefreshData();
        }

        private void fld_btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void fld_btnOK_Click(object sender, EventArgs e)
        {
            STToolbarsController objToolbarsController = new STToolbarsController();

            foreach (STToolbarsInfo objToolbarsInfo in lstMainFormToolbar)
            {
                objToolbarsController.UpdateObject(objToolbarsInfo);
            }

            THSApp.InitToolbarOfMainForm();
            this.Close();
        }

    }
}